/**
 * 全局变量
 */
var selectUserId = '';
$(function(){
    /*
    * 加载列表数据
    * */
    $('#listGrid').datagrid({
        url:ROOT_PATH+'/risk/matrix/queryResultList.shtml',
        queryParams:{
            sort:'addTime',
            order:'desc'
        },
        idField:'id',
        fitColumns:true,
        pagination:false,
        rownumbers:true,
        singleSelect:true,
        sortOrder:true,
        striped:true,
        fit:true,
        columns:[[
            {field:'id',width:10,checkbox:true},
            {field:'grade',title:'风险后果严重等级',width:10},
            {field:'people',title:'人员伤害',width:10},
            {field:'money',title:'财产损失',width:10},
            {field:'environment',title:'环境影响',width:10},
            {field:'prestige',title:'声誉影响',width:10},
            {field:'sort',title:'排序',width:10},
            {field:'addUserName',title:'登记人员',width:10},
            {field:'addDeptName',title:'登记部门',width:10},
            {field:'addTime',title:'登记时间',width:10},
            {field:'remarks',title:'备注',width:10}
        ]]
    });
    /**
     * 加载下拉列表信息
     *
     */
    //绑定按钮事件
    $("#btn_risk_matrix_result_add").on("click",function(){
        addResult();
    });
    $("#btn_risk_matrix_result_edit").on("click",function(){
        editResult();
    });
    $("#btn_risk_matrix_result_delete").on("click",function(){
        deleteResult();
    });
    //查询按钮绑定事件
    $("#btn_search").on('click',function(){
        searchFun();
    });
    $('#btn_clear').on('click',function(){
        $('#searchForm1').form('clear');
        $('#searchForm2').form('clear');
    });

});

/**
 * 打开风险等级新增页面
 */
function addResult(){
    WindowManager.openLayer({
        type: 2,
        title: '新增风险后果信息',
        area: ['800px', '70%'],
        content: ROOT_PATH + '/risk/matrix/toAddResultPage.shtml',
        callBack:function(data){//窗口关闭后的回调函数
            $('#listGrid').datagrid("reload");
        }
    });
            /*var index = top.layer.open({
                type: 2,
                title: '新增风险后果信息',
                area: ['800px', '70%'],
                content: ROOT_PATH + '/risk/matrix/toAddResultPage.shtml',
                end:function(){
                    $('#listGrid').datagrid("reload");
                }
            });*/
}
/**
 * 打开风险可能性等级编辑页面
 */
function editResult(){
    var selectedRow =  $('#listGrid').datagrid('getSelected');
    if(selectedRow){
        var businessId = selectedRow.id;
        WindowManager.openLayer({
            type: 2,
            title: '编辑风险后果信息',
            area: ['800px', '50%'],
            content: ROOT_PATH + '/risk/matrix/toEditResultPage.shtml?businessId='+businessId,
            callBack:function(data){//窗口关闭后的回调函数
                $('#listGrid').datagrid("reload");
            }
        });
        /*var index = top.layer.open({
            type: 2,
            title: '编辑风险后果信息',
            area: ['800px', '50%'],
            content: ROOT_PATH + '/risk/matrix/toEditResultPage.shtml?businessId='+businessId,
            end:function(){
                $('#listGrid').datagrid("reload");
            }
        });*/
    }else{
        layer.alert("请选择数据！");
    }

}
/**
 * 删除风险等级信息
 */
function deleteResult(){

    var selectedRow =  $('#listGrid').datagrid('getSelected');
    if(selectedRow) {
        var businessId = selectedRow.id;
        var index = layer.confirm("确定删除改行数据吗？",{btn:["确定","取消"]},function(){
            $.ajax({
                type:'post',
                url:ROOT_PATH + '/risk/matrix/deleteResultInfo.shtml?businessId='+businessId,
                dataType:"json",
                success:function(result){
                    if (result.success){
                        layer.msg(result.message,{time:1000,icon:1},function(){
                            $('#listGrid').datagrid('reload');
                        });
                    }else{
                        layer.msg(result.message,{time:1000,icon:1},function(){
                        });
                    }
                }
            });
        })
    }else{
        layer.alert("请选择数据！");
    }
}
